/*
 * @Author: Yuelei 
 * @Date: 2018-03-19 15:32:16 
 * @Last Modified by: mikey.zhaopeng
 * @Last Modified time: 2018-03-21 19:44:13
 */
import React from 'react';
import {Link} from 'react-router-dom'
import MUtil from 'util/mm.jsx'
import User from 'service/user-service.jsx'


const _user=new User;
const _mm=new MUtil
class NavTop extends React.Component{
    constructor(props){
        super(props);
        this.state={
            username: _mm.getStorage('userInfo').username || ''
        }
    }
    onLogout(){
       _user.logout().then(res=>{
           _mm.removeStorage('userInfo');
           window.location.href='/login';
       },errMsg=>{
           _mm.erroeTips(errMsg);
       })
        // 退出登录
    }
    render(){
        return(
            <div className="navbar navbar-default top-navbar" >
            <div className="navbar-header">
               
                <Link className="navbar-brand" to="/"><b>商城</b>管理系统</Link>
            </div>

            <ul className="nav navbar-top-links navbar-right">
            
                <li className="dropdown">
                    <a className="dropdown-toggle" data-toggle="dropdown" href="javasscript:;" aria-expanded="false">
                        <i className="fa fa-user fa-fw"></i> 
                       {
                           this.state.username? <span>欢迎{this.state.username}</span>:
                            <span>欢迎您</span>
                       } 
                        <i className="fa fa-caret-down"></i>
                    </a>
                    <ul className="dropdown-menu dropdown-user">
              
                        <li>
                            <a onClick={()=>{this.onLogout()}}>
                            <i className="fa fa-sign-out fa-fw"></i> 
                           <span>退出登录</span> 
                           </a>
                        </li>
                    </ul>
                   
                </li>
               
            </ul>
        </div>
        );
    }

}
export default NavTop

